<?php
class Product_model extends CI_Model{
	public function getProductByOffset($offset,$limit,$publish){
		
		
		$data = array();
		
		$lang = $this->lang->lang();
		
		$this->db->select('p.id, p.sku, p.name, p.price, p.discount, p.quantity, cl.category_name, m.name AS manufacturer_name, p.order, p.public');
		$this->db->from('products p');
		
		$this->db->limit($limit,$offset);
		$this->db->join('categories c','p.category_id = c.id');
		$this->db->join('category_languages cl','cl.category_id = c.id');
		$this->db->join('manufacturers m','m.id = p.manufacturer_id');
		$this->db->join('languages l','l.id = cl.language_id AND l.code =\''.$lang. '\'');
		if($publish != -1)
			$this->db->where('p.public',$publish);
		
		$q = $this->db->get();
		$data = $q->result_array();
		$q->free_result();
		return $data;
		
	}
	
	
	public function getNumofProduct($publish){
		$data = 0;
		if($publish != -1)
			$this->db->where('public',$publish);
		$q = $this->db->get('products');
		$data = $q->num_rows();
		$q->free_result();
		
		return $data;
	}
	
}